package com.picturehistory.core.jersey.model;

import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import com.google.appengine.api.datastore.Key;

@XmlRootElement(name="Article")
@XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)
//@XmlType(propOrder={"key", "x", "y", "title", "hashTag", "body", "created", "modified"})
@PersistenceCapable
public class Article {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	//@net.sf.oval.constraint.NotNull is not working with JDO
	@Persistent
	private Integer x;
	
	@Persistent
	private Integer y;
	
	@Persistent
	private String author;
	
	@Persistent
	private String title;
	
	@Persistent
	private List<String> hashTag;
	
	@Persistent
	private String body;
	
	@Persistent
	private Date created;
	
	@Persistent
	private Date modified;
	
	public Article() {}

	public Article(Integer x, Integer y, String author, String title, List<String> hashTag, String body) {
		super();
		this.x = x;
		this.y = y;
		this.author = author;
		this.title = title;
		this.hashTag = hashTag;
		this.body = body;
		this.created = new Date();
		this.modified = new Date();
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List<String> getHashTag() {
		return hashTag;
	}

	public void setHashTag(List<String> hashTag) {
		this.hashTag = hashTag;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public Integer getX() {
		return x;
	}

	public void setX(Integer x) {
		this.x = x;
	}

	public Integer getY() {
		return y;
	}

	public void setY(Integer y) {
		this.y = y;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getModified() {
		return modified;
	}

	public void setModified(Date modified) {
		this.modified = modified;
	}
	
	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}
	
	public long getNumericId() {
		if (this.key == null) {
			return -1;
		} else {
			return this.key.getId();
		}
	}

	@Override
	public String toString() {
		return "Article [key=" + key + ", x=" + x + ", y=" + y + ", title="
				+ title + ", hashTag=" + hashTag + ", body=" + body
				+ ", created=" + created + ", modified=" + modified + "]";
	}
	
	
}
